from sqlalchemy import Column, Integer, String, ForeignKey, DateTime, Boolean
from .base import Base
from sqlalchemy.orm import relationship

__all__ = [
    'CabinetType', 'SwitchType', 'HardPressurePlateType', 'SoftPressurePlateType', 'CircuitBreakerType'
]


class CabinetType(Base):
    """屏柜类型表（独立枚举表）"""
    __tablename__ = 'cy_cabinet_types'

    id = Column(Integer, primary_key=True, comment='类型ID')
    name = Column(String(50), unique=True, nullable=False, comment='类型名称（如：配电柜、控制柜）')
    description = Column(String(200), comment='类型描述')


class SwitchType(Base):
    """选开类型表（独立枚举表）"""
    __tablename__ = 'cy_switch_types'

    id = Column(Integer, primary_key=True, comment='类型ID')
    name = Column(String(50), unique=True, nullable=False, comment='类型名称（如：空气开关、微型断路器）')
    description = Column(String(200), comment='类型描述')

    def __repr__(self):
        return f"<SwitchType(id={self.id}, name='{self.name}')>"


class HardPressurePlateType(Base):
    """硬压板类型表（独立枚举表）"""
    __tablename__ = 'cy_hard_plate_types'

    id = Column(Integer, primary_key=True, comment='类型ID')
    name = Column(String(50), unique=True, nullable=False, comment='类型名称（如：标准硬压板、特殊硬压板）')
    description = Column(String(200), comment='类型描述')
    primary_type_id = Column(Integer, ForeignKey('cy_plats_types.id'), nullable=False,
                             comment='关联的压板ID')
    plats_types = relationship('PlatsTypes', backref='hard_plate_types')

    def __repr__(self):
        return f"<HardPressurePlateType(id={self.id}, name='{self.name}')>"


class SoftPressurePlateType(Base):
    """软压板类型表（独立枚举表）"""
    __tablename__ = 'cy_soft_plate_types'

    id = Column(Integer, primary_key=True, comment='类型ID')
    name = Column(String(50), unique=True, nullable=False, comment='类型名称（如：标准软压板、特殊软压板）')
    description = Column(String(200), comment='类型描述')

    primary_type_id = Column(Integer, ForeignKey('cy_plats_types.id'), nullable=False,
                             comment='关联的压板ID')
    plats_types = relationship('PlatsTypes', backref='soft_plate_types')

    def __repr__(self):
        return f"<SoftPressurePlateType(id={self.id}, name='{self.name}')>"


class CircuitBreakerType(Base):
    """空开类型表（独立枚举表）"""
    __tablename__ = 'cy_air_breaker_types'

    id = Column(Integer, primary_key=True, comment='类型ID')
    name = Column(String(50), unique=True, nullable=False, comment='类型名称（如：自动空开、手动空开）')
    description = Column(String(200), comment='类型描述')

    def __repr__(self):
        return f"<CircuitBreakerType(id={self.id}, name='{self.name}')>"


class DeviceTypes(Base):
    """空开类型表（独立枚举表）"""
    __tablename__ = 'cy_device_types'

    id = Column(Integer, primary_key=True, comment='类型ID')
    name = Column(String(50), unique=True, nullable=False, comment='类型名称（如：装置）')
    description = Column(String(200), comment='类型描述')

    def __repr__(self):
        return f"<DeviceTypes(id={self.id}, name='{self.name}')>"


class PlatsTypes(Base):
    """空开类型表（独立枚举表）"""
    __tablename__ = 'cy_plats_types'

    id = Column(Integer, primary_key=True, comment='类型ID')
    name = Column(String(50), unique=True, nullable=False, comment='类型名称（如：压板类型）')
    description = Column(String(200), comment='类型描述')

    def __repr__(self):
        return f"<PlatsTypes(id={self.id}, name='{self.name}')>"


cabinet_types = CabinetType.__table__
plats_types = PlatsTypes.__table__

air_breaker_types = CircuitBreakerType.__table__
soft_plate_types = SoftPressurePlateType.__table__
hard_plate_types = HardPressurePlateType.__table__
switch_types = SwitchType.__table__
device_types = DeviceTypes.__table__